<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>建设单位--项目列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<div class="layui-row">
	<div class="layui-col-xs6">
		<form class="layui-form" action="" style="padding: 10px 0;">
			<div class="layui-input-inline">
				<input style="width:200px;" type="text" id="prjName1" name="prjName" placeholder="已分配项目名称/申报编号" autocomplete="off"
					   class="layui-input">
			</div>
			<input type="button" class="layui-btn" id="leftQuery" lay-filter="leftQuery" value="查询"/>
			<input type="button" class="layui-btn" id="leftClean" lay-filter="leftClean" value="清空"/>
		</form>
	  <table class="layui-hide" id="dataList1" lay-filter="dataList1"></table>
	</div>
	<div class="layui-col-xs6">
		<form class="layui-form searchForm" action="">
			<div class="layui-input-inline">
				<input style="width:200px;" type="text" id="prjName" name="prjName" placeholder="项目名称/申报编号" autocomplete="off"
					   class="layui-input">
			</div>
			<button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
			<input type="button" class="layui-btn" id="rightClean" value="清空"/>
		</form>
		<table class="layui-hide" id="dataList" lay-filter="dataList"></table>
	</div>
</div>

<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="assign">分配</a>
</script>
<script type="text/html" id="barDemo1">
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">移除</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
	
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;
        var configureCom = layui.configureCom;
        var token = sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '';
		
        var iframeId = configureCom.GetQueryString('iframeId');
        var userId = configureCom.GetQueryString('userId');
		/**
		 * 表格1
		 */
		var cols = [[
            {field: 'prjName', title: '建设项目名称'},
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100}
        ]];
        configureCom.tableRender(configure.UNIT_PROJECT_LIST_HTTP, {}, cols, 'dataList', 10, 'full-100', '');
        
		/**
		 * 表格2
		 */
		var cols1 = [[
		    {field: 'prjName', title: '已分配项目名称'},
		    {fixed: 'right', title: '操作', toolbar: '#barDemo1', width: 100}
		]];

		(function loadData(){
			configureCom.tableRenderGet(configure.UNIT_SUPERVISE_PROJECT_LIST_HTTP, {userId: userId}, cols1, 'dataList1', 10, 'full-100', '');
		})()

		
		

		//每行操作
		table.on('tool(dataList)', function (obj) {
		    var data = obj.data;
		    sessionFun.set(configure.SESSION_PROJECT_LIST_DATA, data);
		    sessionFun.remove(configure.SESSION_PROJECT_WAIT_LIST_DATA, data);
			if(obj.event === 'assign'){
				console.log(data)
				var params={
					prjId:data.prjId,
					userId:userId
				}
				configureCom.postDataAjax(configure.COM_SUPERVISE_PROJECT_SAVE_HTTP, params).then(function (res) {
				    if (res.code == 0) {
						configureCom.tableReloadById('dataList1');
				        top.layer.msg('保存成功！');
				    } else {
				        top.layer.alert('保存失败！');
				    }
				});
			}
		});
		
		
        //每行操作
        table.on('tool(dataList1)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_PROJECT_LIST_DATA, data);
			if(obj.event === 'remove'){
                var params = {"id":data.id};
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: configure.COM_SUPERVISE_PROJECT_REMOVE_HTTP+"/"+data.id+"?token="+token,
                    type: 'delete',
                    cache: false,
                    data: {},
                    dataType : "json",
                    success: function (data) {
                        top.layer.close(index);
                        if(data.code==0){
                            configureCom.tableReloadById('dataList1');
                            top.layer.msg('删除成功！');
						}else{
                            top.layer.alert('删除失败！');
						}
                    },
                    error: function (data) {
                        top.layer.close(index);
                        top.layer.alert('删除失败！');
                    }
                });

			}
        });

        $(document).on('click','#leftQuery',function(){
            var prjName = $("#prjName1").val();
            configureCom.tableRenderGet(configure.UNIT_SUPERVISE_PROJECT_LIST_HTTP, {userId: userId, prjName:prjName}, cols1, 'dataList1', 10, 'full-100', '');
        });

        $(document).on('click','#leftClean',function(){
            $("#prjName1").val('');
            configureCom.tableRenderGet(configure.UNIT_SUPERVISE_PROJECT_LIST_HTTP, {userId: userId}, cols1, 'dataList1', 10, 'full-100', '');
        });

        $(document).on('click','#rightClean',function(){
            $("#prjName").val('');
            configureCom.tableRender(configure.UNIT_PROJECT_LIST_HTTP, {}, cols, 'dataList', 10, 'full-100', '');
        });

        //监听搜索
        configureCom.tableSearch();
    });
</script>
</body>
</html>